package com.gu.VO;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.net.ServerSocket;

/**
 * @ProjectName: apartment-management-center
 * @Package: com.gu.VO
 * @ClassName: ServerResponse
 * @Author: gusongliao
 * @Description: 返回包装类
 * @createDate 2021/02/25 11:34
 */
public class ServerResponse {

    private Integer code;
    private String msg;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Object data;

    public ServerResponse() {
    }

    public ServerResponse(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public final static ServerResponse SUCCESS = new ServerResponse(0,"成功",null);

    public static ServerResponse success(Object data) {
        ServerResponse serverResponse = new ServerResponse();
        serverResponse.code = 0;
        serverResponse.msg = "成功";
        serverResponse.data = data;
        return serverResponse;
    }

    public static ServerResponse success(Integer code,Object data) {
        ServerResponse serverResponse = new ServerResponse();
        serverResponse.code = code;
        serverResponse.msg = "成功";
        serverResponse.data = data;
        return serverResponse;
    }

    public static ServerResponse success(Integer code,String msg) {
        ServerResponse serverResponse = new ServerResponse();
        serverResponse.code = code;
        serverResponse.msg = "成功";
        if (!"".equals(msg)) {
            serverResponse.msg = msg;
        }
        return serverResponse;
    }

    public static ServerResponse error(Integer code, String msg) {
        ServerResponse serverResponse = new ServerResponse();
        serverResponse.code = code;
        serverResponse.msg = msg;
        return serverResponse;
    }

    public static ServerResponse error(Integer code, String msg, Object data){
        ServerResponse serverResponse = new ServerResponse();
        serverResponse.code = code;
        serverResponse.msg = msg;
        serverResponse.data = data;
        return serverResponse;
    }
}
